/**
 * @Author: mahai
 * @Date: 2019-10-08
 * @desc: import引入组件使用的高阶组件 --->  按需加载模块
 */
import React, {Component} from "react";

export default function SyncyComponent (importComponent) {
    class SyncyComponent extends Component{
        constructor(props) {
            super(props);
            this.state = {
                component: null,
            };
        }

        async componentDidMount() {
            const { default: component } = await importComponent();

            this.setState({
                component: component
            });
        }

        render() {
            const C = this.state.component;

            return C && <C {...this.props} />

        }

    }

    return SyncyComponent;
}

